package com.example.springcloudribbon.service.impl;

import com.example.springcloudribbon.service.HelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloServiceImpl implements HelloService {

    @Autowired
    RestTemplate template;

    @Override
    @HystrixCommand(fallbackMethod = "error")
    public String sayHello(String name) {
        return template.getForObject("http://SPRINGCLOUD-CLIENT/hi?name=" + name, String.class);
    }


    public String error(String name) {
        return "Dear " + name + ", something was wrong";
    }

}
